#include "iwdg_bsp.h"

extern IWDG_HandleTypeDef hiwdg;

iwdg_obj_t iwdg_obj={
  .iwdg = &hiwdg
};

int iwdg_obj_open(void)
{
  iwdg_obj_t *obj=&iwdg_obj;
  
  obj->iwdg->Instance = IWDG;
  obj->iwdg->Init.Prescaler = IWDG_PRESCALER_64;
  obj->iwdg->Init.Reload = 4095;
  if (HAL_IWDG_Init(obj->iwdg) != HAL_OK)
  {
    Error_Handler();
  }
  return 0;
}

int iwdg_obj_ioctl_refresh(void)
{
  iwdg_obj_t *obj=&iwdg_obj;
  
  HAL_IWDG_Refresh(obj->iwdg);
  return 0;
}

int iwdg_obj_close(void)
{
  return 0;
}